package com.bysj.lms.service.impl;

import com.bysj.lms.pojo.dto.LmsHasDto;
import com.bysj.lms.pojo.entity.Cabinetinfo;
import com.bysj.lms.pojo.entity.LmsHas;
import com.bysj.lms.mapper.LmsHasMapper;
import com.bysj.lms.service.ICabinetinfoService;
import com.bysj.lms.service.ILmsHasService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bysj.lms.utils.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class LmsHasServiceImpl extends ServiceImpl<LmsHasMapper, LmsHas> implements ILmsHasService {

    @Autowired
    LmsHasMapper lmsHasMapper;
    @Autowired
    ICabinetinfoService cabinetinfoService;

    @Override
    public PageInfo<LmsHasDto> findByPage(String uid,String name,String status, Integer page, Integer count) {
        PageHelper.startPage(page,count);
        List<LmsHasDto> lmsHasDtos = lmsHasMapper.find(uid,name,status);
        return new PageInfo(lmsHasDtos);
    }

    @Override
    public boolean handle(String chargerId,String applyId, String status) {
        boolean update = lambdaUpdate().eq(LmsHas::getId, applyId)
                .set(LmsHas::getChargeId,chargerId)
                .set(LmsHas::getHandleTime, LocalDateTime.now())
                .set(LmsHas::getStatus, status).update();
        return update;
    }

    @Override
    public boolean trusteeship(LmsHas lmsHas) {
        lmsHas.setStatus("3");
        boolean update = updateById(lmsHas);
        boolean update1 = cabinetinfoService.lambdaUpdate().eq(Cabinetinfo::getId, lmsHas.getCabinetinfoId())
                .set(Cabinetinfo::getStatus, "1").update();
        return update&&update1;
    }
}
